import java.util.Stack;

public class Day_7_2_合法括号序列 {
    public boolean chkParenthesis(String A, int n) {
        // write code here
        if(A == null || n == 0 || A.length() != n){
            return false;
        }
        char arr[] = A.toCharArray();
        Stack<Character> stack = new Stack<Character>();
        for (int i = 0; i < n; i++) {
            if(arr[i] == '('){
                stack.push(arr[i]);
            }else if(arr[i] == ')'){
                char c = stack.pop();
            }else {
                return false;
            }
        }
        if(!stack.isEmpty()){
            return false;
        }
        return true;
    }
}
